package valueObject
{
	import flash.display.Shape;
	import flash.events.MouseEvent;
	import flash.utils.getTimer;

	/**
	 *炮塔 
	 * @author SXT
	 */
	public class TowerVO extends ExpertVO
	{
		/**
		 *攻击的目标 
		 */
		public var target:BaseVO;
		/**
		 *是否是在建造模式(不准许攻击) 
		 */		
		public var building:Boolean = true;
		/**
		 *攻击距离 
		 */
		public var range:int;
		/**
		 *攻击力 
		 */		
		public var power:Array = [];
		/**
		 * 子弹类型 
		 */		
		public var bulletId:int;
		/**
		 *攻击间隔 
		 */		
		public var interval:int;
		/**
		 *上次开火时间 
		 */		
		public var lastTime:Number = getTimer();
		/**
		 *建造时间 
		 */
		public var creat:int;
		/**
		 *造价 
		 */
		public var price:int;
		/**
		 *子弹序列 
		 */		
		public var bulletList:Vector.<BulletVO> = new Vector.<BulletVO>;
		/**
		 *攻击范围
		 */		
		private var circle:Shape;
		
		public function TowerVO()
		{
			super();
//			this.mouseChildren = false;
			this.mouseEnabled = false;
		}
		
		//隐藏攻击范围
		protected function hideRange(event:MouseEvent):void
		{
			circle.visible = false;
		}
		
		//显示攻击范围
		protected function showRange(event:MouseEvent):void
		{
			circle.visible = true;//显示
		}
		
		//释放塔相关资源
		public function release():void{
			removeEventListener(MouseEvent.MOUSE_OVER,showRange);
			removeEventListener(MouseEvent.MOUSE_OUT,hideRange);
		}
		
		/**
		 *开火 
		 * 判断攻击间隔
		 * 生成子弹
		 */
		public function fire():void{
//			trace(""+target + target.name)
			if((getTimer() - lastTime) >= interval){																//判断攻击间隔
				if(target){
					lastTime = getTimer();
//					for each(var tmp:BulletVO in bulletList){
//						
//					}
					bulletList.push(Game.instance.bulletMag.addBullet(this,bulletId,target));
				}
			}
		}
		
		public function init():void
		{
			addEventListener(MouseEvent.MOUSE_OVER,showRange);
			addEventListener(MouseEvent.MOUSE_OUT,hideRange);
			circle = new Shape();
			circle.alpha = 0.2;
			circle.graphics.beginFill(0x00ff00);//sh.图形属性，填充颜色
			circle.graphics.drawCircle(0,0,range);//sh.图形属性，画矩形
			circle.graphics.endFill();
			circle.x = (this.width >> 1);
			circle.y = (this.height >> 1);
			this.addChild(circle);
		}
	}
}